package thread;

/**
 *守护线程
 * 守护线程
 */
public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread rose = new Thread("肉丝") {
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println(getName() + ":我要跳了嗷！别拦我！");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                System.out.println(getName()+":别拦我!!!");
                System.out.println(getName()+":我TM来辣");
            }
        };
        Thread jack = new Thread("解渴") {
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(getName() + ":肉丝不要啊!!!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                System.out.println("我的肉丝!");
                System.out.println("求你别死!!!");
            }
        };
        rose.start();
        //设置守护线程必须在该线程启动前进行,否则会抛出异常
        jack.setDaemon(true);
        jack.start();
    }
}